package com.flot.yazb.home.setting;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.flot.yazb.R;
import com.flot.yazb.base.BActivity;
import com.flot.yazb.base.BApplication;
import com.flot.yazb.model.user.UserModel;
import com.flot.yazb.widget.utils.SharedPreferencesUtils;
import com.flot.yazb.widget.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;



public class UpdateMsgActivity extends BActivity {


    @BindView(R.id.tvedu)
    EditText tvedu;
    @BindView(R.id.tvincome)
    EditText tvincome;
    @BindView(R.id.tvjob)
    EditText tvjob;
    @BindView(R.id.tvweight)
    EditText tvweight;
    @BindView(R.id.tvheight)
    EditText tvheight;
    @BindView(R.id.tvblood)
    EditText tvblood;
    @BindView(R.id.tvmarry)
    EditText tvmarry;
    @BindView(R.id.tvhomes)
    EditText tvhomes;
    @BindView(R.id.btsavebasemsg)
    Button btsavebasemsg;
    @BindView(R.id.tvchild)
    EditText tvchild;
    @BindView(R.id.tvyidi)
    EditText tvyidi;
    @BindView(R.id.tvleixing)
    EditText tvleixing;
    @BindView(R.id.tvsex)
    EditText tvsex;
    @BindView(R.id.tvparent)
    EditText tvparent;
    @BindView(R.id.tvmeili)
    EditText tvmeili;
    @BindView(R.id.btsavemoremsg)
    Button btsavemoremsg;
    private UserModel selfModel = BApplication.getInstance().getUserModel();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_msg_update);
        ButterKnife.bind(this);
        tvheight.setText(SharedPreferencesUtils.getString(activity,"fix_height",""));
        tvweight.setText(SharedPreferencesUtils.getString(activity,"fix_weight",""));
        tvblood.setText(SharedPreferencesUtils.getString(activity,"fix_blood",""));
        tvedu.setText(SharedPreferencesUtils.getString(activity,"fix_edu",""));
        tvjob.setText(SharedPreferencesUtils.getString(activity,"fix_job",""));
        tvincome.setText(SharedPreferencesUtils.getString(activity,"fix_income",""));
        tvmarry.setText(SharedPreferencesUtils.getString(activity,"fix_marry",""));
        tvhomes.setText(SharedPreferencesUtils.getString(activity,"fix_homes",""));

        tvchild.setText(SharedPreferencesUtils.getString(activity,"fix_child",""));
        tvyidi.setText(SharedPreferencesUtils.getString(activity,"fix_yidi",""));
        tvleixing.setText(SharedPreferencesUtils.getString(activity,"fix_leixing",""));
        tvsex.setText(SharedPreferencesUtils.getString(activity,"fix_sex",""));
        tvparent.setText(SharedPreferencesUtils.getString(activity,"fix_parent",""));
        tvmeili.setText(SharedPreferencesUtils.getString(activity,"fix_meili",""));
    }

    // 2017/9/5  俩个设置接口返回数据格式问题
    @OnClick({R.id.btsavebasemsg, R.id.btsavemoremsg,R.id.iv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btsavebasemsg:
                SharedPreferencesUtils.saveString(activity,"fix_height",tvheight.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_weight",tvweight.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_blood",tvblood.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_edu",tvedu.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_job",tvjob.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_income",tvincome.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_marry",tvmarry.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_homes",tvhomes.getText().toString());
                ToastUtil.showToast(activity,"保存成功");
//                showProgress();
//                FixMsgParmsModel par= new FixMsgParmsModel(selfModel.id,tvheight.getText().toString(),tvweight.getText().toString(),
//                        tvblood.getText().toString(),tvedu.getText().toString(),tvjob.getText().toString(),tvincome.getText().toString()
//                ,tvmarry.getText().toString(),tvhomes.getText().toString());
//                SelfModel.setBaseMsg(par, new BModel.Transit<SelfModel>(this) {
//                    @Override
//                    public void onBorn(SelfModel serializable, String code, String message) {
//                        dismissProgress();
//                        if (code.equals(CodeStub.B_OK)) {
//                            finish();
//                        } else {
//                            ToastUtil.showToast(activity, message);
//                        }
//                    }
//                });
                break;
            case R.id.btsavemoremsg:
                SharedPreferencesUtils.saveString(activity,"fix_child",tvchild.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_yidi",tvyidi.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_leixing",tvleixing.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_sex",tvsex.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_parent",tvparent.getText().toString());
                SharedPreferencesUtils.saveString(activity,"fix_meili",tvmeili.getText().toString());
                ToastUtil.showToast(activity,"保存成功");
//                showProgress();
//                FixMsgParmsModel parmore= new FixMsgParmsModel(
//                        selfModel.id,
//                        tvchild.getText().toString(),
//                        tvyidi.getText().toString(),
//                        tvleixing.getText().toString()
//                        ,tvsex.getText().toString(),
//                        tvparent.getText().toString(),
//                        tvmeili.getText().toString());
//                SelfDetailModel.setDetailMsg(parmore, new BModel.Transit<SelfDetailModel>(this) {
//                    @Override
//                    public void onBorn(SelfDetailModel serializable, String code, String message) {
//                        dismissProgress();
//                        if (code.equals(CodeStub.B_OK)) {
//                            finish();
//                        } else {
//                            ToastUtil.showToast(activity, message);
//                        }
//                    }
//                });
                break;
        }
    }
}
